/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.vsu.cs.piit.vokod.controller;

import ru.vsu.cs.piit.hibernate.GenericDAO.GenericHibernateDAO;
import ru.vsu.cs.piit.vokod.IListListener;
import ru.vsu.cs.piit.vokod.ObservableArrayList;
import ru.vsu.cs.piit.vokod.model.Diagnos;
import ru.vsu.cs.piit.vokod.model.GroupOfDiagnosis;
import ru.vsu.cs.piit.vokod.model.GroupOfTreatment;
import ru.vsu.cs.piit.vokod.model.Treatment;
import ru.vsu.cs.piit.vokod.model.Ward;

/**
 * @author Галчонок
 */
public class Maps {
    static ObservableArrayList<Ward> wardList = new ObservableArrayList(GenericHibernateDAO.findAll(Ward.class));
    static ObservableArrayList<Diagnos> diagnosList = new ObservableArrayList(GenericHibernateDAO.findAll(Diagnos.class));
    static ObservableArrayList<GroupOfDiagnosis> groupOfDiagnosisesList = new ObservableArrayList(GenericHibernateDAO.findAll(GroupOfDiagnosis.class));
    static ObservableArrayList<Treatment> treatmentList = new ObservableArrayList(GenericHibernateDAO.findAll(Treatment.class));
    static ObservableArrayList<GroupOfTreatment> groupOfTreatmentsList = new ObservableArrayList(GenericHibernateDAO.findAll(GroupOfTreatment.class));

    static{
        wardList.AddListener(new ListListener<Ward>());

        diagnosList.AddListener(new ListListener<Diagnos>());

        treatmentList.AddListener(new ListListener<Treatment>());

        groupOfDiagnosisesList.AddListener(new ListListener<GroupOfDiagnosis>());

        groupOfTreatmentsList.AddListener(new ListListener<GroupOfTreatment>());
    }

    static public ObservableArrayList<Ward> getWardList(){
        return wardList;
    }

    static public ObservableArrayList<Diagnos> getDiagnosList(){
        return diagnosList;
    }

    static public ObservableArrayList<Treatment> getTreatmentList(){
        return treatmentList;
    }

    static public ObservableArrayList<GroupOfDiagnosis> getGroupOfDiagnosisesList(){
        return groupOfDiagnosisesList;
    }

    static public ObservableArrayList<GroupOfTreatment> getGroupOfTreatmentsList(){
        return groupOfTreatmentsList;
    }
}

class ListListener<T> implements IListListener<T>{

    public void doSave(T object) {
        GenericHibernateDAO.save(object);
    }

    public void doRemove(T object) {
        GenericHibernateDAO.delete(object);
    }

}
